/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.service;

import br.com.foxline.model.City;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author laverson
 */
@Stateless
public class CityService extends GenericService<City> {

    public CityService() {
        super(City.class);
    }
    
    @Override
    public void save(City entity){
        super.save(entity);
    }
    
    @Override
    public void delete(City entity){
        super.delete(entity);
    }
    
    @Override
    public void update(City entity){
        super.update(entity);
    }
    
    @Override
    public City find(Long id){
        return super.find(id);
    }
    
    @Override
    public List<City> findAll(){
        return super.findAll();
    }
    
    public List<City> autoComplete(String query){
        return findByName(query);
    }
    
    public List<City> findByName(String query){
        List<City> results = getEntityManager().createQuery("select e from " + City.class.getSimpleName() + " e where lower(e.name) like '%" + query.toLowerCase().trim() + "%'").getResultList();
        return results;
    }
    
}
